package com.jlc.o2o.web.superadmin;


import com.jlc.o2o.entity.Area;
import com.jlc.o2o.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("superadmin")
public class AreaController {

    @Autowired
    private AreaService areaService;



    //RequestMapping用value和不用一样的效果，里面带不带“/”也是一样的效果
    @RequestMapping(value = "listareas", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> listAreas(){
        Map<String, Object> map = new HashMap<>();
        List<Area> list = new ArrayList<>();
        try {
            list = areaService.queryArea();
            map.put("rows", list);//rows total 这种写法是针对前台使用ezUI框架而言，这是规定 不能变
            map.put("total", list.size());
        }catch (Exception e){
            e.printStackTrace();
            map.put("success", false);
            map.put("errMsg", e.toString());
        }

        return map;
    }

}
